{% extends 'layout/gallery.htm' %}

{% block g_body %}

{% macro prava(name) %}
<label for='{{name}}'>Práva:</label>
<select name='{{name}}' id='{{name}}'>
<option value="0"> Verejný </option>
<option value="1"> Pre prihlásených </option>
<option value="2"> Súkromný </option>
</select><br/>
{% endmacro %}

{% macro prava_typ(name) %}
<label for='{{name}}'>Typ:</label>
<select name='{{name}}' id='{{name}}'>
<option value="0"> Zakázať</option>
<option value="1"> Povoliť </option>
</select><br/>
{% endmacro %}

<div id='captionbar'>
<h1>Administrácia</h1>  
</div>

{% for e in errors -%}
  <div class='error'>
    {{ e }}
  </div>  
{%- endfor %}
{% for m in messages -%}
  <div class='message'>
    {{ m }}
  </div>  
{%- endfor %}

<div id='tabs'/>
  <ul>
    <li><a href="#tabs-1">Fotky</a></li>
    <li><a href="#tabs-2">Albumy</a></li>
    <li><a href="#tabs-3">Používatelia</a></li>
    <a id="admin_back_to_page" href="index.php">Späť na stránku</a>
  </ul>
  <div id="tabs-1">
            
    <form action='' method='post' enctype="multipart/form-data">
    <fieldset>
    <legend><h2>Pridať fotku:</h2></legend>

    <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />{# 5MB #}

    <label for='photo_album'>Album:</label>
    <select name='photo_album' id='photo_album'>
    {% for item in adminTools.getAlbums %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='photo_caption'>Nadpis:</label>
    <input type='text' name='photo_caption' id='photo_caption'/><br/>
    <label for='photo_file'>Fotka:</label>
    <input type="file" name="photo_file" id="photo_file" /><br/>
    {{_self.prava('photo_perm') }}
    <button type='submit' name='addPhoto'>Pridaj</button>    
    </fieldset>
    </form>

    <form action='' method='post' enctype="multipart/form-data">
    <fieldset>
    <legend><h2>Oprávnenia na fotku:</h2></legend>
    <label for='perm_photo'>Fotka:</label>
    <select name='perm_photo[]' id='perm_photo' multiple='multiple'>
    {% for item in adminTools.getPhotos %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='perm_photo_user'>Používaťeľ:</label>
    <select name='perm_photo_user[]' id='perm_photo_user' multiple='multiple'>
    {% for item in adminTools.getUsers %}      
        <option value="{{item.getID}}"> {{item.getDisplayname}}({{item.getUserName}}) </option>
    {% endfor %}
    </select><br/>
    {{_self.prava_typ('perm_photo_perm')}}
    <button type='submit' name='addPhotoPerms'>Nastav</button>    
    </fieldset>
    </form>


    <form action='' method='post'>
    <fieldset>
    <legend><h2>Editovať fotku:</h2></legend>
    <label for='photo_edit'>Fotka:</label>
    <select name='photo_edit' id='photo_edit'>
    <option value="-1"> -- vyberte fotku -- </option>
    {% for item in adminTools.getPhotos %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='photo_edit_name'>Meno:</label>
    <input type='text' name='photo_edit_name' id='photo_edit_name'/><br/>
    <label for='photo_edit_caption'>Nadpis:</label>
    <input type='text' name='photo_edit_caption' id='photo_edit_caption'/><br/>
    {#<label for='photo_edit_file'>Fotka:</label>
    <input type="file" name="photo_edit_file" id="photo_edit_file" /><br/>#}
    {{_self.prava('photo_edit_perm') }}
    <button type='submit' name='editPhoto'>Uprav</button>
    </fieldset>
    </form>

  </div>
  <div id="tabs-2">
  
    <form action='' method='post'>
    <fieldset>
    <legend><h2>Pridať album:</h2></legend>
    <label for='album'>Rodič:</label>
    <select name='album' id='album'>
    {% for item in adminTools.getAlbums %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='album_name'>Meno:</label>
    <input type='text' name='album_name' id='album_name'/><br/>
    <label for='album_caption'>Nadpis:</label>
    <input type='text' name='album_caption' id='album_caption'/><br/>
    {{_self.prava('album_perm') }}
    <button type='submit' name='addAlbum'>Pridaj</button>
    </fieldset>
    </form>

    <form action='' method='post' enctype="multipart/form-data">
    <fieldset>
    <legend><h2>Oprávnenia na album:</h2></legend>
    <label for='perm_album'>Album:</label>
    <select name='perm_album[]' id='perm_album' multiple='multiple'>
    {% for item in adminTools.getAlbums %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='perm_album_user'>Používaťeľ:</label>
    <select name='perm_album_user[]' id='perm_album_user' multiple='multiple'>
    {% for item in adminTools.getUsers %}      
        <option value="{{item.getID}}"> {{item.getDisplayname}}({{item.getUserName}}) </option>
    {% endfor %}
    </select><br/>
    {{_self.prava_typ('perm_album_perm')}}
    <button type='submit' name='addAlbumPerms'>Nastav</button>
    </fieldset>
    </form>

    <form action='' method='post'>
    <fieldset>
    <legend><h2>Editovať album:</h2></legend>
    <label for='album_edit'>Album:</label>
    <select name='album_edit' id='album_edit'>
    <option value="-1"> -- vyberte album -- </option>
    {% for item in adminTools.getAlbums %}      
        <option value="{{item.getID}}"> {{item.getCaption}}({{item.getPath}}) </option>
    {% endfor %}
    </select><br/>
    <label for='album_edit_name'>Meno:</label>
    <input type='text' name='album_edit_name' id='album_edit_name'/><br/>
    <label for='album_edit_caption'>Nadpis:</label>
    <input type='text' name='album_edit_caption' id='album_edit_caption'/><br/>
    {{_self.prava('album_edit_perm') }}
    <button type='submit' name='editAlbum'>Uprav</button>
    </fieldset>
    </form>
  </div>
  <div id="tabs-3">
  <form action='' method='post'>
    <fieldset>
    <legend><h2>Editovať používateľa:</h2></legend>
    <label for='user_edit'>Používateľ:</label>
    <select name='user_edit' id='user_edit'>
    <option value="-1"> -- vyberte používateľa -- </option>
    {% for item in adminTools.getUsers %}      
        <option value="{{item.getID}}"> {{item.getDisplayname}}({{item.getUserName}}) </option>
    {% endfor %}
    </select><br/>
    <label for='user_edit_name'>Meno:</label>
    <input type='text' name='user_edit_name' id='user_edit_name'/><br/>
    <label for='user_edit_surname'>Priezvisko:</label>
    <input type='text' name='user_edit_surname' id='user_edit_surname'/><br/>
    <label for='user_edit_nick'>Prezývka:</label>
    <input type='text' name='user_edit_nick' id='user_edit_nick'/><br/>
    <label for='user_edit_mail'>Email:</label>
    <input type='text' name='user_edit_mail' id='user_edit_mail'/><br/>
    <button type='submit' name='editUser'>Uprav</button>
    </fieldset>
    </form>
  </div>
  <script type='text/javascript'>
    $("#tabs").tabs();

     $("#photo_edit").change(function(){      
      $.getJSON('admin.php', {action:"getPhotoInfo", ajax: true, id : $("#photo_edit").val()}, function(data) {           
        $("#photo_edit_name").val(data.name);
        $("#photo_edit_caption").val(data.caption);
        $("#photo_edit_perm").val(data.permissions);        
      });
    });

    $("#album_edit").change(function(){      
      $.getJSON('admin.php', {action:"getAlbumInfo", ajax: true, id : $("#album_edit").val()}, function(data) {           
        $("#album_edit_name").val(data.name);
        $("#album_edit_caption").val(data.caption);
        $("#album_edit_perm").val(data.permissions);        
      });
    });

    $("#user_edit").change(function(){      
      $.getJSON('admin.php', {action:"getUserInfo", ajax: true, id : $("#user_edit").val()}, function(data) {           
        $("#user_edit_name").val(data.name);
        $("#user_edit_surname").val(data.surname);
        $("#user_edit_nick").val(data.nick);
        $("#user_edit_mail").val(data.email);
      });
    });
  </script>
</div>


{% endblock %}